package com.sikaryofficial.backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sikaryofficial.backend.domain.entity.PointsDetail;
import com.sikaryofficial.backend.mapper.PointsDetailMapper;
import com.sikaryofficial.backend.service.IPointsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 积分流水Service业务层处理
 *
 * @author qinjinyuan
 * @date 2023-10-27
 */
@Service
public class PointsDetailServiceImpl extends ServiceImpl<PointsDetailMapper, PointsDetail> implements IPointsDetailService {
    @Autowired
    private PointsDetailMapper pointsDetailMapper;
    @Override
    public int countOwnerPointsFlow(Long ownerId) {
        if (Objects.isNull(ownerId) || ownerId <= 0L) {
            return 0;
        }
        return pointsDetailMapper.selectCount(new LambdaQueryWrapper<PointsDetail>()
                .eq(PointsDetail::getCreatedBy, ownerId)
                .eq(PointsDetail::getHasValid, 0)
                .eq(PointsDetail::getDeletedVersion, 0L)
        );
    }
}
